/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package br.jm.financeiro.view;

import br.jm.financeiro.base.eao.EaoException;
import br.jm.financeiro.entity.Carga;
import br.jm.financeiro.sistema.eao.CargaEao;
import java.io.Serializable;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;

/**
 *
 * @author joao
 */
public class CargaBean implements Serializable {

    private static final long serialVersionUID = 1L;
    private Carga selectedCarga;
    private final CargaEao cargaEAO;

    public CargaBean() throws EaoException {
        cargaEAO = CargaEao.getInstance();
        selectedCarga = new Carga();
        
        selectedCarga = cargaEAO.getPorId(1);
    }

    public void alterar(ActionEvent actionEvent) {
        FacesMessage msg = null;

        try {
            cargaEAO.edit(selectedCarga);
            LoginBean.AtualizaLog("", "ALTERAÇÃO STATUS CARGA: ".concat(selectedCarga.getDscCarga()));
            msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Status da Carga Alterado com Sucesso",selectedCarga.getDscCarga());
        } catch (Exception e) {
            msg = new FacesMessage(FacesMessage.SEVERITY_WARN, "Erro ao Alterar Status da Carga: " + selectedCarga.getDscCarga(),e.getMessage());
        } finally {
            FacesContext.getCurrentInstance().addMessage(null, msg);
        }
    }

    public Carga getSelectedCarga() {
        return selectedCarga;
    }

    public void setSelectedCarga(Carga selectedCarga) {
        this.selectedCarga = selectedCarga;
    }

    
}
